define(['jquery', 'mapController', "controller","coordtransform"], function ($) {
    // 方法重定向
    var c = require("controller");
    var mapController = require("mapController");
    var coordtransform = require("coordtransform");


    return {
        //地图展示
        init:function (form_elementData) {
            $('#container').height($('#mapModal .modal-dialog').height()-$('#mapModal .modal-header').height()-$('#mapModal .modal-footer').height()-50);
            var map = mapController.initMap();
            map.init('container');
            var Satellite=map.setMapType();
            map.setMapControl();
            $(".maptype>div:eq(0)").on('click',function () {
                Satellite.hide();
            });
            $(".maptype>div:eq(1)").on('click',function () {
                Satellite.show();
            });
            var infoWindow= map.createInfoWindow();

            $.each(form_elementData,function (i,point) {
                var space;

                var property =JSON.parse(point.property);
                var lable='';

                $.each(property.path,function (ii,v) {
                    var gj= coordtransform.wgs84togcj02(mapController.changeDMSToLng(v.lng),mapController.changeDMSToLat(v.lat));
                    lable+='<label>'+v.name+'<br/>'+v.lng+'<br/>'+v.lat+'</label>';
                    v.lng=gj[0];
                    v.lat=gj[1];
                   /* if(i==0){
                        map.setCenter([v.lng,v.lat])
                    }*/

                });

               // var html='<li><span>'+(point.type==252?'往返':c.getElementType(point.type))+':'+point.name+'</span>'+lable+'</li>';
                var clone=$('.cloneDIV>div').clone();
                clone.find('.box-body').append(lable);
                clone.find('.box-title').append((point.type==252?'往返':c.getElementType(point.type))+':'+point.name);
                clone.show();
                $('.ele-location').append(clone);
                switch(point.type.toString())
                {
                    case "252":
                    case "254": //画航线

                        space=map.createPolyline(property.path,{
                            strokeColor: '#e63f00',
                            strokeOpacity: 1,
                            strokeWeight: 3,
                            zIndex:10,
                            title:point.name,
                            strokeStyle: "solid"
                        });

                        break;
                    case '255': // 多边形空域
                        space=map.createPolygon(property.path,{
                            fillColor:'#289BEC',
                            fillOpacity:0.4,
                            strokeColor:'#40A4FB',
                            zIndex:10,
                            title:point.name,
                            strokeWeight:2
                        });
                        break;
                    case "253":// 圆形空域
                        space=map.createCircle(property.path,{
                            fillColor:'#289BEC',
                            fillOpacity:0.4,
                            strokeColor:'#40A4FB',
                            zIndex:10,
                            radius:property.radius*1,
                            title:point.name,
                            strokeWeight:2
                        });
                        break;
                    case '0'://起降点
                        space=map.createMark({lnglat:property.path[0],title:point.name});
                        space.setIcon('../../images/marker_smart_packing.png',[16,16]);
                        break;
                    case '1'://途径点
                        space=map.createMark({lnglat:property.path[0],title:point.name});
                        space.setIcon('../../images/marker_smart_packing.png',[16,16]);
                        break;
                    case '2'://加油咪
                        space=map.createMark({lnglat:property.path[0],title:point.name});
                        space.setIcon('../../images/marker_smart_packing.png',[16,16]);
                        break;
                    case '3'://机场
                        space=map.createMark({lnglat:property.path[0],title:point.name});
                        space.setIcon('../../images/airport.png',[16,16]);

                        break;
                }
                map.addOverlay(space);
                clone.find('.box-title').data('path',property.path);
                map.setFitView();

            });

            $('.ele-location').on('click','h3.box-title',function () {
                var path = $(this).data('path');
                map.setCenter([path[0].lng,path[0].lat]);
                infoWindow.setContent($(this).html());
                infoWindow.open(map, [path[0].lng,path[0].lat]);
            });
        }
    }
});



